<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body{
      padding: 200px 300px;
    }
    .active{
      background: pink;
    }
  </style>
</head>
<body>
  <!-- emmet -->
  <button class="active">1</button>
  <button>2</button>
  <button>3</button>
  <button>4</button>
  <button>5</button>

  <script>
    // var btn1 = document.querySelectorAll('button')[0]
    // var btn2 = document.querySelectorAll('button')[1]
    // var btn3 = document.querySelectorAll('button')[3]
    // btn1.onclick = function(){}
    // btn2.onclick = function(){}
    // btn3.onclick = function(){}

    var list = document.querySelectorAll('button')  // 数组

    for(var i = 0; i < list.length; i++) {  // 给五个 button注册事件
      list[i].onclick = function() {

        for(var i = 0; i < list.length; i++) {  // 将所有人的颜色去掉
          list[i].className = ''
        }

        this.className = 'active'  // 给我自己添加颜色
      }
    }

  </script>
</body>
</html>